package com.koron.css2.serviceManage.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.bean.PubReceiptBean;
import com.koron.css2.baseConfig.mapper.PubReceiptMapper;
import com.koron.css2.baseConfig.queryBean.PubReceiptQueryBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

/**
 * 单据列表
 * @author admin
 *
 */
public class ProcessConfigList implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {

		@SuppressWarnings("rawtypes")
		MessageBean<List> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", List.class);
		try {
			PubReceiptQueryBean bean = JsonUtils.objectToPojo(req.getData(), PubReceiptQueryBean.class);
			PubReceiptMapper mapper = factory.getMapper(PubReceiptMapper.class, "_default");
			String setCode = mapper.getWorkflowApp(bean.getCompanyNo());
			List<PubReceiptBean> list = mapper.selectPubReceiptList(bean);
			list.stream().forEach(t -> t.setSetCode(setCode));
			info.setData(list);
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription(e.getMessage());
			logger.error(e.getMessage(), e);
		}
		return info;
	}
}
